<template>
  <div class="back-top" v-show="showBackBtn" @click="handleScroll">
    <svg
      width="20"
      height="20"
      viewBox="0 0 48 48"
      fill="none"
      xmlns="http://www.w3.org/2000/svg">
      <path
        d="M24.0083 14.1005V42"
        stroke="#8d8d8d"
        stroke-width="3"
        stroke-linecap="square"
        stroke-linejoin="miter" />
      <path
        d="M12 26L24 14L36 26"
        stroke="#8d8d8d"
        stroke-width="3"
        stroke-linecap="square"
        stroke-linejoin="miter" />
      <path
        d="M12 6H36"
        stroke="#8d8d8d"
        stroke-width="3"
        stroke-linecap="square"
        stroke-linejoin="miter" />
    </svg>
  </div>
</template>
<script>
export default {
  name: "BackTop",
  data() {
    return {
      showBackBtn: false,
    };
  },
  mounted() {
    window.addEventListener("scroll", () => {
      if (window.scrollY > 100) {
        this.showBackBtn = true;
        return;
      }
      this.showBackBtn = false;
    });
  },
  methods: {
    handleScroll(e) {
      console.log(e, "eee");
      e.preventDefault();
      window.scroll({
        top: 0,
        left: 0,
        behavior: "smooth",
      });
    },
  },
};
</script>
<style scoped lang="scss">
.back-top {
  position: fixed;
  bottom: 100px;
  right: 10px;
  width: 46px;
  height: 46px;
  overflow: hidden;
  border: 1px solid #8d8d8d;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  > svg {
    width: 30px;
    height: 30px;
  }
}
.back-top:hover {
  background: #e7e7e7;
}
</style>
